<?php
/**
 * User: Mykola B.
 * Date: 3/3/13
 * Time: 12:47 PM
 */
namespace geo {
    class Cluster implements \Iterator, \Countable
    {
        /**
         * @var Point
         */
        public $origin;

        /**
         * @var Point[]
         */
        private $collection = array();
        private $position = 0;

        public function __construct(Point $point) {
            $this->position = 0;
            $this->origin = $point;
            $this->push($point);
        }

        public function push(Point $point) {
            array_push($this->collection, $point);
        }

        public function last() {
            return $this->collection[count($this->collection) - 1];
        }

        public function first() {
            return $this->collection[0];
        }

        public function count() {
            return count($this->collection);
        }

        public function rewind() {
            $this->position = 0;
        }

        public function current() {
            return $this->collection[$this->position];
        }

        public function key() {
            return $this->position;
        }

        public function next() {
            ++$this->position;
        }

        public function valid() {
            return isset($this->collection[$this->position]);
        }
    }
}
